package cn.xcstudenth.myapplication.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import java.nio.Buffer;
import java.util.List;

import cn.xcstudenth.myapplication.ConstantUtils;
import cn.xcstudenth.myapplication.R;
import cn.xcstudenth.myapplication.texviewutils.TextHtmlUtils;

/**
 * Created by 赵航 on 2020/8/13.
 * WeChat: zhao--hang--
 */
public class TextViewHtmlFragment extends Fragment {
    private View mView;
    private List<String> mData;
    private TextView mTextView;

    public TextViewHtmlFragment(List<String> list) {
        this.mData = list;
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mView = inflater.inflate(R.layout.fragment_text_html, null);
        initView();
        return mView;
    }

    private void initView() {
        mTextView=(TextView)mView.findViewById(R.id.text_view);
        StringBuilder builder = new StringBuilder();
        for (String datum : mData) {
            builder.append(datum);
            builder.append("\\n\\r");
        }
        //数学公式不能翻译
        TextHtmlUtils.setHtml(mTextView,builder.toString(),17, ConstantUtils.ZERO);
    }
}
